package com.smartleanx.module.hrm.service.examine.examineReview;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.smartleanx.module.hrm.controller.admin.examine.examineReview.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineReview.ExamineReviewDO;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.util.object.BeanUtils;

import com.smartleanx.module.hrm.dal.mysql.examine.examineReview.ExamineReviewMapper;

import static com.smartleanx.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.smartleanx.module.hrm.enums.ErrorCodeConstants.*;

/**
 * 审核关联 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineReviewServiceImpl implements ExamineReviewService {

    @Resource
    private ExamineReviewMapper examineReviewMapper;

    @Override
    public Integer createExamineReview(ExamineReviewSaveReqVO createReqVO) {
        // 插入
        ExamineReviewDO examineReview = BeanUtils.toBean(createReqVO, ExamineReviewDO.class);
        examineReviewMapper.insert(examineReview);
        // 返回
        return examineReview.getId();
    }

    @Override
    public void updateExamineReview(ExamineReviewSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineReviewExists(updateReqVO.getId());
        // 更新
        ExamineReviewDO updateObj = BeanUtils.toBean(updateReqVO, ExamineReviewDO.class);
        examineReviewMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineReview(Integer id) {
        // 校验存在
        validateExamineReviewExists(id);
        // 删除
        examineReviewMapper.deleteById(id);
    }

    private void validateExamineReviewExists(Integer id) {
        if (examineReviewMapper.selectById(id) == null) {
//            throw exception(EXAMINE_REVIEW_NOT_EXISTS);
        }
    }

    @Override
    public ExamineReviewDO getExamineReview(Integer id) {
        return examineReviewMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineReviewDO> getExamineReviewPage(ExamineReviewPageReqVO pageReqVO) {
        return examineReviewMapper.selectPage(pageReqVO);
    }

}